<?php

// +----------------------------------------------------------------------
// | 行为日志模型
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\model\ucenter;

use think\facade\Db;
use yicmf\tools\FlowSn;

class UserTask extends Common
{


    // 定义关联方法
    public function user()
    {
        return $this->belongsTo(User::class);
    }


    /**
     * 写入修改
     * @param $data
     */
    public static function onBeforeInsert($data)
    {
        $data['status'] = isset($data['status']) ? $data['status'] : 0;
        $data['task_no'] = isset($data['task_no'])?$data['task_no']:FlowSn::build(5);
        $data['ip'] = request()->ip();
//        $data['os'] = request()->server('HTTP_USER_AGENT');
        $data['param'] = '';
    }


    public function getCreateTimeAttr($value, $data)
    {
        return $value ? $value : date('Y-m-d H:i:s', $data['createtime']);
    }
    public function getStatusTextAttr($value, $data)
    {
        if ($data['task_type'] == 1 || $data['task_type'] == 2 || $data['task_type'] == 3) {
            $arr= [
                0=>'访问',
                1=>'通过',
                3=>'未提交',
                4=>'审核中',
                5=>'待激活',
                6=>'拒绝',
                7=>'二卡',
                8=>'已激活',
                10=>'提交失败',
                11=>'待首刷',
                12=>'已注销',
                13=>'无效',
                99=>'重复提交',
                20=>'降级通过',
            ];
            return isset($arr[$data['step']])?$arr[$data['step']]:'未知';
        }else{
            $arr= [
                0=>'已提交',
                1=>'进行中',
                2=>'已完结',
                3=>'已失败',
                4=>'已驳回',
            ];
            return isset($arr[$data['status']])?$arr[$data['status']]:'未知';
        }
    }
    public function getStatusColorAttr($value, $data)
    {
        $arr= [
            0=>'text-red',
            1=>'color_ec',
            2=>'text-black',
            3=>'text-red',
        ];
        return isset($arr[$data['status']])?$arr[$data['status']]:'text-black';
    }

    protected $type = ['submit_info' => 'array'];
}
